 <?php
class Payment extends CActiveRecord {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return "ts_payment";
    }
    
    public function attributeLabels() {
        return array(
            "order_id" => "รหัสเอกสาร",
            "payment_type_id" => "ประเภทการชำระเงิน",
            "payment_status" => "สถานะการชำระเงิน",
            "payment_description" => "รายละเอียด",
            "payment_create_date" => "วันที่",
            "payment_modified_date" => "วันที่แก้ไข",
        );
    }
    
//    public function rules() {
//        return array(
//            array("payment_type_name_thai, payment_type_name_eng", "required",'message'=>'กรุณากรอกข้อมูลให้ครบ'),
//            array("payment_type_name_thai", "length", "max" => 255),
//            array("payment_type_name_eng", "length", "max" => 255),
//        );
//    }
    
    public function search() {
        $criteria = new CDbCriteria;
        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }
    
    public function beforeValidate() {
        if ($this->isNewRecord) {
            $this->payment_type_status = 1;
            $this->payment_type_create_date = new CDbExpression("NOW()");
        }
        else
        {
//            $this->payment_type_modified_date = new CDbExpression("NOW()");
        }

        return parent::beforeValidate();
    }
}
?>
